import pymysql
from pymysql.cursors import DictCursor

conn = pymysql.connect(
    host='127.0.0.1',
    port=3306,
    user='root',
    password='123456',
    db='my_test',
    charset='utf8',
    cursorclass=pymysql.cursors.DictCursor
)

# 获取游标
cursor = conn.cursor()

# # 查询
# sql1 = "select * from student;"
# cursor.execute(sql1)

# 更新语句, 必须要commit确认提交更新操作
sql2 = "INSERT INTO student VALUES (12, '坚果', 18, '男', 155444888);"
cursor.execute(sql2)
conn.commit()

# 获取一条数据
# data1 = cursor.fetchone()
# data2 = cursor.fetchone()
# print(data1)
# print(data2)

# # 获取所有数据
data = cursor.fetchall()
print(data)

# 关闭游标
cursor.close()
# 关闭连接
conn.close()